import time
from random import randint
setGlobalDuration(30)

beginPythonInst(1)
soundfont(duration=4)
endPythonInst()

proc = startCsound()

scl = scale('Em')

rnd = loopseg(25,35)

time.sleep(2)

def pit(amp):
    if ti1.getBeat() == 1 and (ti1.getBar() % 4) == 0:
        ti1.regenerate(16, randint(60,90), randint(40,70), randint(30,60))
    dict = {'soundfont': {}}
    dict['soundfont']['midipitch'] = scl[rnd.next()]
    dict['soundfont']['pan'] = random.randint(0,7)*0.125
    dict['soundfont']['amplitude'] = amp
    sendEvent(1, dict, proc)

ti1 = rhythmPattern(.1, pit, 16, 90, 60, 20)
ti1.start()
ti1.play()


